﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace X23.Extensions.AttributeExtensions
{
    /// <summary>
    /// 自定义授权
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class X23AuthorizeAttribute : Attribute
    {
        /// <summary>
        /// 自定义授权
        /// </summary>
        /// <param name="controllerName">控制器名称</param>
        /// <param name="permissions">权限列表</param>
        public X23AuthorizeAttribute(string controllerName, params string[] permissions)
        {
            ControllerName = controllerName;
            if (permissions.Length == 0)
            {
                throw new Exception($"请添加具体权限！controllerName={controllerName}，permissionsLength={permissions.Length}");
            }
            PermissionList = permissions.ToList();
        }
        /// <summary>
        /// 控制器名称
        /// </summary>
        public string ControllerName { get; set; }
        /// <summary>
        /// 权限列表
        /// </summary>
        public List<string> PermissionList { get; set; }
    }
}
